﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vsm="clr-namespace:System.Windows;assembly=PresentationFramework"
    xmlns:transformbox="clr-namespace:TransformBox;assembly=TransformBox">

    <Style x:Key="TransformBoxStyle" TargetType="{x:Type transformbox:TransformBox}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type transformbox:TransformBox}">
                    <Grid>
                        <vsm:VisualStateManager.VisualStateGroups>

                            <vsm:VisualStateGroup x:Name="VisibilityTransformBox">
                                <vsm:VisualState x:Name="CollapsedTransformBox" />
                                <vsm:VisualState x:Name="VisibleTransformBox">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="PART_Root" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>

                            <vsm:VisualStateGroup x:Name="OperationTransformBox">
                                <vsm:VisualState x:Name="NaNOperation" />
                                <vsm:VisualState x:Name="RotateOperation">
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="PART_RotateA" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#20000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateB" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#20000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateC" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#20000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateD" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#20000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateE" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#20000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateF" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#20000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateG" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#20000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateH" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#20000000" Duration="0" />

                                        <ColorAnimation Storyboard.TargetName="PART_SkewAC" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_SkewCE" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_SkewEG" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_SkewGA" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="SkewOperation">
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="PART_RotateA" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateB" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateC" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateD" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateE" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateF" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateG" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateH" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />

                                        <ColorAnimation Storyboard.TargetName="PART_SkewAC" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#30000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_SkewCE" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#30000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_SkewEG" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#30000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_SkewGA" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#30000000" Duration="0" />
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="ScaleOperation">
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="PART_RotateA" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateB" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateC" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateD" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateE" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateF" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateG" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateH" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />

                                        <ColorAnimation Storyboard.TargetName="PART_SkewAC" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_SkewCE" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_SkewEG" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_SkewGA" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="TranslateOperation">
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="PART_RotateA" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateB" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateC" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateD" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateE" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateF" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateG" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_RotateH" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="#01000000" Duration="0" />

                                        <ColorAnimation Storyboard.TargetName="PART_SkewAC" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_SkewCE" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_SkewEG" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                        <ColorAnimation Storyboard.TargetName="PART_SkewGA" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" To="#01000000" Duration="0" />
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>

                        </vsm:VisualStateManager.VisualStateGroups>
                        <Canvas Name="PART_Root" Visibility="Collapsed">
                            <Canvas.Resources>

                                <Style x:Key="RotateStyle" TargetType="Ellipse">
                                    <Setter Property="Width" Value="30"/>
                                    <Setter Property="Height" Value="30"/>
                                    <Setter Property="StrokeThickness" Value="0"/>
                                    <Setter Property="Fill" Value="#01000000"/>
                                    <Setter Property="RenderTransform">
                                        <Setter.Value>
                                            <TranslateTransform X="-15" Y="-15"/>
                                        </Setter.Value>
                                    </Setter>
                                </Style>

                                <Style x:Key="SkewStyle" TargetType="Line">
                                    <Setter Property="StrokeThickness" Value="10"/>
                                    <Setter Property="Stroke" Value="#01000000"/>
                                </Style>

                                <Style x:Key="TranslateStyle" TargetType="Path">
                                    <Setter Property="StrokeThickness" Value="1"/>
                                    <Setter Property="Stroke" Value="#AA000000"/>
                                    <Setter Property="Fill" Value="#01000000"/>
                                </Style>

                                <Style x:Key="ScaleStyle" TargetType="Rectangle">
                                    <Setter Property="Width" Value="8"/>
                                    <Setter Property="Height" Value="8"/>
                                    <Setter Property="StrokeThickness" Value="1"/>
                                    <Setter Property="Stroke" Value="#AA000000"/>
                                    <Setter Property="Fill" Value="#01000000"/>
                                    <Setter Property="RenderTransform">
                                        <Setter.Value>
                                            <TranslateTransform X="-4" Y="-4"/>
                                        </Setter.Value>
                                    </Setter>
                                </Style>

                                <Style x:Key="CentralStyle" TargetType="Rectangle" BasedOn="{StaticResource ScaleStyle}">
                                    <Setter Property="StrokeThickness" Value="2"/>
                                    <Setter Property="Stroke" Value="#00FFFF"/>
                                </Style>

                            </Canvas.Resources>

                            <ContentPresenter x:Name="PART_Presenter" Panel.ZIndex="1">
                                <ContentPresenter.RenderTransform>
                                    <MatrixTransform x:Name="PART_Transform" />
                                </ContentPresenter.RenderTransform>
                            </ContentPresenter>

                            <Grid x:Name="HelperPanel" Background="#01000000" Width="{Binding ElementName=Root, Path=ActualWidth}" Height="{Binding ElementName=Root, Path=ActualHeight}" Panel.ZIndex="9001" />

                            <Path x:Name="PART_TranslateElement" Style="{StaticResource TranslateStyle}" Panel.ZIndex="9001">
                                <Path.Data>
                                    <PathGeometry>
                                        <PathFigure StartPoint="{Binding PointA, RelativeSource={RelativeSource TemplatedParent}}">
                                            <LineSegment Point="{Binding PointB, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            <LineSegment Point="{Binding PointC, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            <LineSegment Point="{Binding PointD, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            <LineSegment Point="{Binding PointE, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            <LineSegment Point="{Binding PointF, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            <LineSegment Point="{Binding PointG, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            <LineSegment Point="{Binding PointH, RelativeSource={RelativeSource TemplatedParent}}"/>
                                            <LineSegment Point="{Binding PointA, RelativeSource={RelativeSource TemplatedParent}}"/>
                                        </PathFigure>
                                    </PathGeometry>
                                </Path.Data>
                            </Path>

                            <Ellipse x:Name="PART_RotateA" Canvas.Left="{Binding PointA.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointA.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9002" Style="{StaticResource RotateStyle}" />
                            <Ellipse x:Name="PART_RotateB" Canvas.Left="{Binding PointB.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointB.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9003" Style="{StaticResource RotateStyle}" />
                            <Ellipse x:Name="PART_RotateC" Canvas.Left="{Binding PointC.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointC.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9004" Style="{StaticResource RotateStyle}" />
                            <Ellipse x:Name="PART_RotateD" Canvas.Left="{Binding PointD.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointD.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9005" Style="{StaticResource RotateStyle}" />
                            <Ellipse x:Name="PART_RotateE" Canvas.Left="{Binding PointE.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointE.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9006" Style="{StaticResource RotateStyle}" />
                            <Ellipse x:Name="PART_RotateF" Canvas.Left="{Binding PointF.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointF.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9007" Style="{StaticResource RotateStyle}" />
                            <Ellipse x:Name="PART_RotateG" Canvas.Left="{Binding PointG.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointG.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9008" Style="{StaticResource RotateStyle}" />
                            <Ellipse x:Name="PART_RotateH" Canvas.Left="{Binding PointH.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointH.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9009" Style="{StaticResource RotateStyle}" />

                            <Line x:Name="PART_SkewAC" X1="{Binding PointA.X, RelativeSource={RelativeSource TemplatedParent}}" Y1="{Binding PointA.Y, RelativeSource={RelativeSource TemplatedParent}}" X2="{Binding PointC.X, RelativeSource={RelativeSource TemplatedParent}}" Y2="{Binding PointC.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9010" Style="{StaticResource SkewStyle}" />
                            <Line x:Name="PART_SkewCE" X1="{Binding PointC.X, RelativeSource={RelativeSource TemplatedParent}}" Y1="{Binding PointC.Y, RelativeSource={RelativeSource TemplatedParent}}" X2="{Binding PointE.X, RelativeSource={RelativeSource TemplatedParent}}" Y2="{Binding PointE.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9011" Style="{StaticResource SkewStyle}" />
                            <Line x:Name="PART_SkewEG" X1="{Binding PointE.X, RelativeSource={RelativeSource TemplatedParent}}" Y1="{Binding PointE.Y, RelativeSource={RelativeSource TemplatedParent}}" X2="{Binding PointG.X, RelativeSource={RelativeSource TemplatedParent}}" Y2="{Binding PointG.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9012" Style="{StaticResource SkewStyle}" />
                            <Line x:Name="PART_SkewGA" X1="{Binding PointG.X, RelativeSource={RelativeSource TemplatedParent}}" Y1="{Binding PointG.Y, RelativeSource={RelativeSource TemplatedParent}}" X2="{Binding PointA.X, RelativeSource={RelativeSource TemplatedParent}}" Y2="{Binding PointA.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9013" Style="{StaticResource SkewStyle}" />

                            <Rectangle x:Name="PART_ScaleA" Canvas.Left="{Binding PointA.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointA.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9014" Style="{StaticResource ScaleStyle}" />
                            <Rectangle x:Name="PART_ScaleB" Canvas.Left="{Binding PointB.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointB.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9015" Style="{StaticResource ScaleStyle}" />
                            <Rectangle x:Name="PART_ScaleC" Canvas.Left="{Binding PointC.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointC.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9016" Style="{StaticResource ScaleStyle}" />
                            <Rectangle x:Name="PART_ScaleD" Canvas.Left="{Binding PointD.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointD.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9017" Style="{StaticResource ScaleStyle}" />
                            <Rectangle x:Name="PART_ScaleE" Canvas.Left="{Binding PointE.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointE.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9018" Style="{StaticResource ScaleStyle}" />
                            <Rectangle x:Name="PART_ScaleF" Canvas.Left="{Binding PointF.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointF.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9019" Style="{StaticResource ScaleStyle}" />
                            <Rectangle x:Name="PART_ScaleG" Canvas.Left="{Binding PointG.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointG.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9020" Style="{StaticResource ScaleStyle}" />
                            <Rectangle x:Name="PART_ScaleH" Canvas.Left="{Binding PointH.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointH.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9021" Style="{StaticResource ScaleStyle}" />

                            <Rectangle x:Name="PART_CentralPoint" Canvas.Left="{Binding PointCenter.X, RelativeSource={RelativeSource TemplatedParent}}" Canvas.Top="{Binding PointCenter.Y, RelativeSource={RelativeSource TemplatedParent}}" Panel.ZIndex="9022" Style="{StaticResource CentralStyle}" />
                        </Canvas>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>